package me.pplay.playtalk.adapter;

import me.pplay.playtalk.R;
import me.pplay.playtalk.bean.Face;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class FaceAdapter extends BaseAdapter {
	private Context context;
	private String[] faces;
	private int tab_index;

	public FaceAdapter(Context context, int tab_index, String[] faces) {
		this.context 	= context;
		this.faces  	= faces;
		this.tab_index  = tab_index;
	}

	@Override
	public int getCount() {
		return faces == null ? 0 : faces.length;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ImageView iv = null;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.smiley_item, null);
			iv = (ImageView) convertView.findViewById(R.id.imageview);
			convertView.setTag(iv);
		} else {
			iv = (ImageView) convertView.getTag();
		}
		System.out.println(",,,,,,,,,,,,,,,,,:"+faces[position] + "   "+ tab_index);
		if(tab_index < 2)
			iv.setImageResource(Face.getInstance(context).faceMap.get("(" + faces[position] + ")"));
		else
			iv.setImageBitmap(Face.getInstance(context).bitMaps.get(faces[position]));
		return convertView;
	}

}
